import { Webpage } from "@/api/common";
import http from "@/utils/http";

/**
 * Invoice
 */
export interface Invoice {
    address?: string;
    bank?: string;
    bankAccount?: string;
    buyer?: string;
    createTime?: Date;
    creator?: string;
    fileKey?: string;
    finisher?: string;
    id?: number;
    invoiceCount?: number | string;
    invoiceType?: string;
    month?: string;
    phone?: string;
    remark?: string;
    status?: string;
    taxNumber?: string;
    updateTime?: Date;
    [property: string]: any;
}

/**
 *
 * CommonTemplate
 */
export interface CommonTemplate {
    address?: string;
    bank?: string;
    bankAccount?: string;
    buyer?: string;
    createTime?: Date;
    id?: number;
    phone?: string;
    taxNumber?: string;
    updateTime?: Date;
    [property: string]: any;
}

/**
 * InvoiceTrack
 */
export interface InvoiceTrack {
    createTime?: Date;
    id?: number;
    invoiceId?: number;
    payload?: string;
    status?: string;
    user?: string;
}


export function page(webpage: Webpage<Invoice>) {
    return http.post<Webpage<Invoice>>('/invoice/page', webpage)
}

export function getStatistic(queryCondition: Invoice, type: string, seller: string) {
    queryCondition.status = type
    queryCondition.seller = seller
    return http.post('/invoice/getStatistic', queryCondition)
}

export function getById(id: string) {
    return http.post<Invoice>(`/invoice/getById?id=${id}`)
}

export function updateInvoice(invoice: Invoice) {
    return http.post<Invoice>(`/invoice/updateInvoice`, invoice)
}

export function addInvoice(invoice: Invoice, sellerName: string) {
    console.log(sellerName, 'sellerName')
    const target = {}
    Object.assign(target, invoice, {
        seller: sellerName
    })
    return http.post<Invoice>(`/invoice/addInvoice`, target)
}

export function removeInvoice(id: string | number) {
    return http.post(`/invoice/removeInvoice?id=${id}`)
}

export function changeAddedStatus(id: Invoice) {
    return http.post<Invoice>(`/invoice/changeAddedStatus?id=${id}`)
}

export function finishAddedStatus(id: Invoice) {
    return http.post<Invoice>(`/invoice/finishAddedStatus?id=${id}`)
}

export function getInvoiceTrackById(id: number | string) {
    return http.post(`/invoice/getInvoiceTrackById?id=${id}`)
}

export function addInvoiceTrack(invoiceTrack: InvoiceTrack) {
    return http.post(`/invoice/addInvoiceTrack`, invoiceTrack)
}

export function checkHasTemplate(buyer: number | string, seller: string) {
    return http.post(`/invoice/checkHasTemplate?buyer=${buyer}&seller=${seller}`)
}

export function addCommonTemplate(template: CommonTemplate) {
    return http.post(`/invoice/addCommonTemplate`, template)
}

export function saveOrUpdateTemplate(template: CommonTemplate) {
    return http.post(`/invoice/saveOrUpdateTemplate`, template)
}

export function listAllTemplate(seller: string) {
    return http.post<CommonTemplate[]>(`/invoice/listAllTemplate?seller=${seller}`)
}

export function queryTemplate(query: any) {
    return http.post<CommonTemplate[]>(`/invoice/queryTemplate`, query)
}

export function removeTemplate(id: string | number) {
    return http.post(`/invoice/removeTemplate?id=${id}`)
}

export function saveComment(comment: any) {
    return http.post(`/invoice/saveComment`, comment)
}

export function getComment(invoiceId: string) {
    return http.post(`/invoice/getComment`, {}, {
        params: {
            id: invoiceId
        }
    })
}

export function deleteComment(id: string) {
    return http.post(`/invoice/deleteComment`, {}, {
        params: {
            id: id
        }
    })
}

export function ocrInvoice(file: any) {
    return http.post(`/invoice/ocrInvoice`, file)
}

export function getInvoiceStruct(invoiceId: string | number) {
    return http.post(`/invoice/getInvoiceStruct`, {}, {
        params: {
            invoiceId: invoiceId
        }
    })
}
